------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--[[

    角色界面

]]--
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- 控件
    local Widget = require "widgets/widget"
    local Image = require "widgets/image"
    local UIAnim = require "widgets/uianim"
    local Screen = require "widgets/screen"
    local AnimButton = require "widgets/animbutton"
    local ImageButton = require "widgets/imagebutton"
    local Menu = require "widgets/menu"
    local Text = require "widgets/text"
    local TEMPLATES = require "widgets/redux/templates"
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- image api
    local BASE_ATLAS = "images/widgets/hutao_inspect_hud.xml"
    local BUFF_ICON_ATLAS = "images/widgets/hutao_talent_buff_icon.xml"
    local function get_image(image_name)
        return TUNING.HUTAO_INSPECT_HUD_FNS.get_image(image_name)
    end
    local function get_info(index)
        return TUNING.HUTAO_INSPECT_HUD_FNS.get_info(index)
    end
    local move_debug_event_install = function()    end
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- 挂载函数，方便动态修改
    TUNING.HUTAO_INSPECT_HUD_FNS.create_character_page = function(inst,root)            
        ----------------------------------------------------------------------
        --- page 节点
            local page = root:AddChild(Widget())
            page:Hide()
            root.inst:ListenForEvent("page_display",function(_,cmd)
                if cmd == "display_character_page" then
                    page:Show()
                else
                    page:Hide()
                end
            end)
        ----------------------------------------------------------------------
        --- level box
            local level_box = page:AddChild(Image(get_image("page_character_level_box")))
            level_box:SetPosition(-430,80)
            local level_box_text = level_box:AddChild(Text(CODEFONT,80,"0",{ 74/255 , 0/255 ,0/255 , 1}))
            level_box_text:SetPosition(30,150)
        ----------------------------------------------------------------------
        --- 文本
            local text_font = CODEFONT
            local text_size = 45
            local text_color = { 74/255 , 0/255 ,0/255 , 1}
            ------------------------------------------------------------------
            --- 血量上限
                local text_max_health = page:AddChild(Text(text_font,text_size,"血量上限",text_color))                
                -- move_debug_event_install(text_max_health:AddChild(Image(BASE_ATLAS,"xp.tex")),root)
                text_max_health:SetPosition(-490,90)
            ------------------------------------------------------------------
            --- 速度
                local text_speed = page:AddChild(Text(text_font,text_size,"速度",text_color))                
                -- move_debug_event_install(text_max_health:AddChild(Image(BASE_ATLAS,"xp.tex")),root)
                text_speed:SetPosition(-490,10)
            ------------------------------------------------------------------
            --- 体力系数
                local text_physical_power = page:AddChild(Text(text_font,text_size,"体力系数",text_color))                
                text_physical_power:SetPosition(-490,-70)
            ------------------------------------------------------------------
            --- 理智上限
                local text_max_sanity = page:AddChild(Text(text_font,text_size,"理智上限",text_color))                
                -- move_debug_event_install(text_max_sanity:AddChild(Image(BASE_ATLAS,"xp.tex")),root)
                text_max_sanity:SetPosition(-320,90)
            ------------------------------------------------------------------
            --- 攻击系数
                local text_damage_mult = page:AddChild(Text(text_font,text_size,"攻击系数",text_color))                
                text_damage_mult:SetPosition(-320,10)
            ------------------------------------------------------------------
            --- 火伤
                local text_fire_damage_mult = page:AddChild(Text(text_font,text_size,"火伤系数",text_color))                
                text_fire_damage_mult:SetPosition(-320,-70)
        ----------------------------------------------------------------------
        --- level bar
            local level_bar = page:AddChild(Widget())
            level_bar:SetPosition(-600,160)
            -- move_debug_event_install(level_bar,root)
            local level_bar_fill = level_bar:AddChild(Image(BASE_ATLAS,"exp_bar_blue.tex"))
            level_bar_fill:SetPosition(0,0)
            -- local delta = FRAMES
            -- level_bar.inst:DoPeriodicTask(FRAMES,function()
            --     -- level_bar_fill:SetScale(current,1)
            -- end)
            local level_bar_frame = level_bar:AddChild(Image(BASE_ATLAS,"exp_bar_frame.tex"))

            local xp_icon = page:AddChild(Image(BASE_ATLAS,"xp.tex"))
            xp_icon:SetPosition(-400,179)
            local xp_text = xp_icon:AddChild(Text(CODEFONT,25,"0000",{ 74/255 , 0/255 ,0/255 , 1}))
            xp_text:SetPosition(80 + 15,0)

            local function update_xp_text()
                local current_exp = inst.replica.hutao_com_level_sys:GetExp()
                local max_exp = inst.replica.hutao_com_level_sys:GetExpMax()
                local exp_precent = math.min(current_exp/max_exp,1)
                level_bar_fill:SetScale(exp_precent,1)
                xp_text:SetString(""..current_exp.." / "..max_exp)

                local current_level = inst.replica.hutao_com_level_sys:GetLevel()
                level_box_text:SetString(""..current_level)

                if not inst.replica.hutao_com_level_sys:IsLevelUpLocking() then
                    level_bar_fill:SetTexture(BASE_ATLAS,"exp_bar_blue.tex")
                else
                    level_bar_fill:SetTexture(BASE_ATLAS,"exp_bar_red.tex")
                end
            end
            update_xp_text()
            page.inst:ListenForEvent("hutao_com_level_sys_update",update_xp_text,inst)
        ----------------------------------------------------------------------
        --- page_character_buff_box
            local buff_box = page:AddChild(Image(BASE_ATLAS,"page_character_buff_box.tex"))
            buff_box:SetPosition(430,80)
        ----------------------------------------------------------------------
        --- page_character_info_box
            local info_box = page:AddChild(Image(BASE_ATLAS,"page_character_info_box.tex"))
            info_box:SetPosition(0,-280)
            local info_str = info_box:AddChild(Text(CODEFONT,45,"",{ 0/255 , 0/255 ,0/255 , 1}))
            page.inst:ListenForEvent("set_info",function(_,index)
                local pt,str,size = get_info(index)
                if pt and str and size then
                    info_str:SetString(str)
                    info_str:SetPosition(pt.x,pt.y)
                    info_str:SetSize(size)
                else
                    info_str:SetString("")
                    info_str:SetPosition(0,0)
                    info_str:SetSize(45)
                end

            end)
        ----------------------------------------------------------------------
        --- 主图标
            local main_icon = page:AddChild(Image(BUFF_ICON_ATLAS,"main_icon.tex"))
            main_icon:SetPosition(0,80)
        ----------------------------------------------------------------------
        --- buff box
            if TUNING.HUTAO_INSPECT_HUD_FNS.buff_box_create then
                TUNING.HUTAO_INSPECT_HUD_FNS.buff_box_create(inst,page)
            end
            -- print("77777777")
        ----------------------------------------------------------------------
        ---
            return page
        ----------------------------------------------------------------------
    end